Structuring a messages API call requires using the multi-role chat format (system/user/assistant) instead of the legacy single-string prompt, enabling coherent multi-turn conversations.
Modern LLM APIs have moved away from the older completion-style API, which used a simple prompt string, to a structured "messages" array (often called the Chat Completion or Messages API) . The core of this change is the introduction of distinct roles for each message, allowing the model to understand the flow of a conversation. A properly structured call includes an array of message objects, each containing a role and content. The primary roles are system (setting the assistant's behavior), user (the end-user's input), and assistant (the model's previous responses) .
For example, an API call for a customer support bot would construct a messages array starting with a system message to define the assistant's role. This is followed by a series of user and assistant message pairs representing the conversation history, ending with the latest user input that the model needs to respond to . This structured format allows for true conversational AI, as the model can reference earlier parts of the exchange, which the legacy 'prompt' string could not do. Both OpenAI and Anthropic APIs follow this pattern, with the key difference being that Anthropic provides a top-level system parameter instead of a system role message in its messages array .